package cc.toprank.syncdatatask.config;

import com.toprank.druid.store.jdbc.Config;
import com.toprank.druid.store.jdbc.SqlTemplate;
import com.toprank.druid.store.jdbc.SqlTemplateFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

//连接rabbitMQ的基本配置
@Configuration
public class SqlTemplateConfig {

	private Properties properties = new Properties();

	private final String CONF_NAME = "canal.properties";
	@Bean
	public SqlTemplate getSqlTemplate() {
		try {
			InputStream in = SqlTemplateConfig.class.getClassLoader().getResourceAsStream(CONF_NAME);
			properties.load(in);
		} catch (IOException e) {
			throw new RuntimeException("Load config[" + CONF_NAME + "] error ", e);
		}

		Config config = new Config();
		config.setParameter("jdbc.url", properties.getProperty("url"));
		config.setParameter("jdbc.username", properties.getProperty("username"));
		config.setParameter("jdbc.password", properties.getProperty("password"));
		config.setWorkThreads(10);
		config.setIdentity("cloud-sync");
		return SqlTemplateFactory.create(config);
	}

}
